package com.zhang.mqtt.handler;

import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.MessagingException;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @Author 超chao
 * @Description 消息接收处理类
 * @Date 2025/7/24/周四 13:41
 * @Version 1.0
 */
@Component
public class ReceiveMessageHandler implements MessageHandler {
    @Override
    public void handleMessage(Message<?> message) throws MessagingException {
        MessageHeaders headers = message.getHeaders();
        String topic = Objects.requireNonNull(headers.get("mqtt_receivedTopic")).toString();
        System.out.println("主题：" + topic);
        System.out.println("消息：" + message.getPayload());
    }
}
